home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / pascal / window.zip / WBIOS.ASM < prev    next >
Assembly Source File  |  1984-06-17  |  23KB  |  1,065 lines

  1.     page    56,132
  2.     title    WBIOS   Window BIOS extension
  3.     .sall
  4. ;
  5. ; Written 1984 By J. Eric Roskos; public domain.
  6. ; No support is provided by the author; you must make any desired
  7. ; revisions yourself.
  8. ;
  9. ; This program provides an extension to the BIOS function calls,
  10. ; functions 40H-43H.  For a description of the calls, see the Turbo
  11. ; Pascal program WDEMO.PAS, which also shows the preferred way of
  12. ; using the functions.  Note, however, that this BIOS extension is
  13. ; independent of any particular language, and will work with any
  14. ; program that does its I/O through the ROM BIOS's "WRITE_TTY"
  15. ; function (the plain MS-DOS display driver does this, for instance).
  16. ;
  17. ; There are a few enhancements to the IBM BIOS call: TABs are handled
  18. ; properly, BELs produce a more bell-like sound, and there is a "Raw"
  19. ; mode (although you'll have to add the function call to set it your-
  20. ; self) in which all characters are displayed as-is, without translation
  21. ; for CR, LF, BEL, etc.  There is also an option to turn end-of-line
  22. ; wraps on or off, although again you must add the function call.
  23. ; To turn these modes on, set the variables "wrap" and "raw" as
  24. ; explained below in the comments.  (These features were included in
  25. ; the program for future expansion, but have never been tested, and
  26. ; aren't guaranteed to work).
  27. ;
  28.  
  29. ;
  30. ; Macros
  31. ;
  32.  
  33. ;
  34. ; wto: write message to display.  Append cr/lf unless crsup=nocr
  35. ;
  36.  
  37. wto    macro    msg,crsup
  38.     local    msgstr,around
  39.  
  40.     jmp    around
  41.  
  42. msgstr    db    msg
  43.     ifb    <crsup>
  44.     db    0DH,0AH
  45.     endif
  46.     db    '$'
  47.  
  48. around:    push    ax
  49.     push    bx
  50.     push    si
  51.     push    di
  52.     push    bp
  53.  
  54.     mov    si,offset msgstr
  55.     call    putc
  56.  
  57.     pop    bp
  58.     pop    di
  59.     pop    si
  60.     pop    bx
  61.     pop    ax
  62.  
  63.     endm
  64.  
  65. prtreg    macro    rg,msg    ; put register rg with message msg on display
  66.  
  67.     push    ax
  68.  
  69.     mov    ax,rg
  70.     call    prtax
  71.     wto    msg,nocr
  72.  
  73.     pop    ax
  74.     endm
  75.  
  76.  
  77. ;
  78. ; Code Segment
  79. ;
  80.  
  81. cseg        segment para public 'code'
  82.         assume    cs:cseg,ds:cseg,ss:cseg,es:nothing
  83.  
  84.         org    100H
  85. ;
  86. ; COM program startup
  87. ;
  88. cpstart        proc    far
  89.         jmp    near ptr start
  90. cpstart        endp
  91.  
  92. ;
  93. ; Local Procedures
  94. ;
  95. lcpos        dw    0E60H
  96.  
  97. putc        proc    near    ; write a string to display W/O DOS intervention
  98.         push    es
  99.         push    ax
  100.         mov    ax,crt_seg
  101.         mov    es,ax
  102.         mov    di,cs:lcpos
  103. putc1:
  104.         mov    al,cs:[si]
  105.         cmp    al,'$'
  106.         je    putc2
  107.         cmp    al,0dH
  108.         jne    putc3
  109.         mov    cs:lcpos,0E60H
  110.         mov    di,0E60H
  111.         jmp    putc4
  112. putc3:
  113.         mov    es:[di],al
  114.         inc    di
  115.         inc    di
  116. putc4:
  117.         inc    si
  118.         jmp    putc1
  119.  
  120. putc2:
  121.         mov    cs:lcpos,di
  122.         pop    ax
  123.         pop    es
  124.         ret
  125.  
  126. putc        endp
  127.  
  128. prtnum        proc    near    ; print half a byte on screen
  129.         push    ds    ; this procedure is used by prtax below
  130.         push    es
  131.  
  132.         push    cs
  133.         pop    ds
  134.  
  135.         push    bx
  136.         mov    bx,crt_seg
  137.         mov    es,bx
  138.         mov    bx,offset xltab
  139.         xlatb
  140.         mov    bx,cs:lcpos
  141.         mov    es:[bx],al
  142.         inc    cs:lcpos
  143.         inc    cs:lcpos
  144.  
  145.         pop    bx
  146.         pop    es
  147.         pop    ds
  148.         ret
  149. xltab        db    '0123456789ABCDEF'
  150. prtnum        endp
  151.  
  152. prtax        proc    near    ; print contents of ax register on screen
  153.         push    cx    ; all registers are preserved
  154.         push    ax
  155.         mov    al,ah
  156.         mov    cl,4
  157.         shr    al,cl
  158.         call    prtnum
  159.         pop    ax
  160.         push    ax
  161.         mov    al,ah
  162.         and    al,0Fh
  163.         call    prtnum
  164.         pop    ax
  165.         push    ax
  166.         mov    cl,4
  167.         shr    al,cl
  168.         call    prtnum
  169.         pop    ax
  170.         push    ax
  171.         and    al,0Fh
  172.         call    prtnum
  173.         pop    ax
  174.         pop    cx
  175.         ret
  176. prtax        endp
  177.  
  178. ;
  179. ; BIOS call dispatcher
  180. ;
  181.  
  182. ;
  183. ; data area
  184. ;
  185.  
  186. ;
  187. ; vector to ROM BIOS
  188. ;
  189.  
  190. romoff        dw    ?
  191. romseg        dw    ?
  192.  
  193. ;
  194. ; display variables
  195. ;
  196.  
  197. active_page    db    ?    ; parameters for wtty (window I/O) proc.
  198. crt_mode    db    ?
  199. color        db    7
  200. rt_edge        db    79
  201. bot_edge    db    24
  202. lf_edge        db    0
  203. top_edge    db    0
  204. wd_width    db    79    ; window width and height (really the coords of
  205. wd_height    db    24    ; bottom corner relative to strt of window)
  206. wrap        db    0    ; 0=don't CRLF at right margin, 1=do
  207. raw        db    0    ; 0=xlate cr, lf, etc, 1=display w/o xlation
  208. crt_seg        dw    ?    ; segment for CRT display RAM
  209.  
  210. ;
  211. ; clock
  212. ;
  213.  
  214. tick        dw    0    ; 1/18th second counter
  215. tock        dw    0    ; every-5-seconds counter (18.2 Hz adjust)
  216. clk_oset    dw    0    ; save area for displaced clock int handler
  217. clk_seg        dw    0
  218.  
  219. ;
  220. ; window stack:
  221. ;   0[wsp] = left edge of window
  222. ;   1[wsp] = top edge of window
  223. ;   2[wsp] = right edge of window
  224. ;   3[wsp] = bottom edge of window
  225. ;   4[wsp] = cursor address (2 bytes)
  226. ;   6[wsp] = offset of window save area (2 bytes)
  227. ;   8[wsp] = segment of window save area (2 bytes)
  228. ;  10[wsp] = number of frames (1 byte)
  229. ;
  230.  
  231. wssize        equ    13         ; number of bytes in window stack frame
  232. wsframes    equ    15         ; number of windows that can be stacked
  233.  
  234. wsp        dw    offset wsend ; display window stack pointer
  235. wstack        db    wssize*wsframes dup (?) ; display window save stack
  236. wsend         equ    this word    ; bottom of stack
  237.         db    wssize dup (?) ; extra frame in case of user error
  238.  
  239. ;
  240. ; window queue: save area for windows
  241. ;
  242.  
  243. wqp        dw    offset qbase ; next avail byte in window queue
  244. wqsize        equ    8192         ; size of window queue - ok to tune
  245. qlim        dw    ?         ; max address in window queue
  246.  
  247. ;
  248. ;
  249.  
  250. temp        dw    ?         ; used when fixing up stack for return
  251.  
  252. ;
  253. ; jump table for our BIOS functions
  254. ;
  255.  
  256. jmptab        label    word
  257.         dw    offset    setwindow
  258.         dw    offset    pushwindow
  259.         dw    offset    rstwindow
  260.         dw    offset    frame
  261. tablen        equ    $-jmptab
  262.  
  263.  
  264. ;
  265. ; the dispatcher
  266. ;
  267.  
  268. disp        proc    far
  269.  
  270.         ;
  271.         ; see if it's one of our functions
  272.         ;
  273.  
  274.         cmp    ah,14        ; write TTY function
  275.         jne    tryrcp
  276.         jmp    ourfn
  277. tryrcp:        cmp    ah,3        ; read cursor position
  278.         jne    tryscp
  279.         jmp    readcsr
  280. tryscp:        cmp    ah,2        ; set cursor position
  281.         je    adjxy        ; have to adjust coordinates
  282.         cmp    ah,6        ; scroll screen up
  283.         jne    trysd        ; have to adjust corners
  284.         jmp    adjsc
  285. trysd:        cmp    ah,7        ; scroll screen down
  286.         jne    tryus        ; adjust corners
  287.         jmp    adjsc
  288. tryus:        cmp    ah,40H        ; one of our new functions?
  289.         jl    callbios    ; no, call the BIOS
  290.         jmp    ourfn
  291.  
  292. callbios:
  293.         push    cs:romseg    ; not one of ours; call BIOS
  294.         push    cs:romoff
  295.         ret
  296.  
  297. ;
  298. ; adjust x and y coordinates for set-cursor-position
  299. ;
  300. adjxy:
  301.         push    dx        ; save caller's dx
  302.  
  303.         add    dh,cs:top_edge    ; adjust the coordinates
  304.         cmp    dh,cs:bot_edge
  305.         jle    adjxy1
  306.  
  307.         ; if below the bottom edge, scroll up a line
  308.  
  309.         push    ax        ; save caller's registers
  310.         push    bx
  311.         push    cx
  312.         push    dx
  313.         push    si
  314.         push    di
  315.         mov    ax,0601H    ; scroll up one line
  316.         mov    cx,0        ; in the current window
  317.         mov    dh,cs:wd_height
  318.         mov    dl,cs:wd_width
  319.         mov    bh,cs:color
  320.         int    10H
  321.         pop    di        ; restore caller's registers
  322.         pop    si
  323.         pop    dx
  324.         pop    cx
  325.         pop    bx
  326.         pop    ax
  327.  
  328.         mov    dh,cs:bot_edge        ; now set cursor to bottom
  329.  
  330. adjxy1:        add    dl,cs:lf_edge
  331.         cmp    dl,cs:rt_edge
  332.         jle    adjxy2
  333.         mov    dl,cs:rt_edge
  334.  
  335.         ; fix up stack so BIOS's IRET will return to
  336.         ; our adjxy3 label
  337.  
  338. adjxy2:        mov    cs:temp,ax    ; save ax (can't push it!)
  339.         push    ax        ; a dummy flag register save
  340.         push    cs        ; return cs
  341.         mov    ax,offset adjxy3 ; return ip
  342.         push    ax
  343.         mov    ax,cs:temp    ; restore saved ax
  344.         jmp    callbios    ; and call the BIOS
  345.  
  346. adjxy3:
  347.         pop    dx        ; back from BIOS now: restore caller's
  348.         iret            ; dx, and return.
  349.  
  350. ;
  351. ; adjust corners for scroll
  352. ;
  353. adjsc:
  354.         push    bx
  355.         add    ch,cs:top_edge    ; adjust row posn of upper left
  356.         cmp    ch,cs:bot_edge
  357.         jle    adjsc1
  358.         mov    ch,cs:bot_edge
  359. adjsc1:        add    cl,cs:lf_edge    ; adjust column posn of upper left
  360.         cmp    cl,cs:rt_edge
  361.         jle    adjsc2
  362.         mov    cl,cs:rt_edge
  363. adjsc2:        add    dh,cs:top_edge    ; adjust row posn of lower right
  364.         cmp    dh,cs:bot_edge
  365.         jle    adjsc3
  366.         mov    dh,cs:bot_edge
  367. adjsc3:        add    dl,cs:lf_edge    ; adjust column posn of lower right
  368.         cmp    dl,cs:rt_edge
  369.         jle    adjsc4
  370.         mov    dl,cs:rt_edge
  371. adjsc4:        mov    bl,cs:bot_edge    ; adjust number of lines to scroll
  372.         sub    bl,cs:top_edge
  373.         cmp    al,bl
  374.         jle    adjsc5
  375.         mov    al,bl
  376. adjsc5:        pop    bx
  377.         jmp    callbios
  378.  
  379. readcsr:                ; read cursor position
  380.         push    ds        ; save registers that must be kept
  381.         push    bx
  382.  
  383.         mov    ax,40H        ; switch to ROM BIOS data segment
  384.         mov    ds,ax
  385.         mov    bl,bh        ; get param page number into bx
  386.         xor    bh,bh
  387.         sal    bx,1        ; convert to cursor table offset
  388.         mov    dx,[bx+50H]    ; read csr posn from cursor table
  389.         mov    cx,word ptr 60H ; read csr mode from mode word
  390.         push    cs        ; switch to our data segment
  391.         pop    ds
  392.         sub    dh,top_edge    ; adjust position for window corner
  393.         sub    dl,lf_edge
  394.  
  395.         ; make sure cursor address is in range -- adjust if not
  396.  
  397.         cmp    dh,0        ; c